<?php
	/**
	 * 评论管理
	 */
	 class CommentController extends AuthController{
	 	
		private $model;
		
		public function __init(){
			parent::__init();
			$this->model = K('GoodsComment');
		}
		
		/**
		 * 显示所有商品评论
		 */
		public function index(){
			$total = M()->join('__goodscomment__ gc JOIN __goods__ g JOIN __users__ u ON gc.goods_gid=g.gid AND gc.users_uid=u.uid')->count();
			$page = new Page($total,10,10);
			$comms = M()->field('gcid,gc_content,gc_time,gc_tag,gid,goods_name,username')->join('__goodscomment__ gc JOIN __goods__ g JOIN __users__ u ON gc.goods_gid=g.gid AND gc.users_uid=u.uid')->order('gc_time DESC')->limit($page->limit())->all();
			$this->assign('page',$page->show(3));
			$this->assign('comms',$comms);
			$this->display();
		}
		
		/**
		 * 删除一个评论
		 */
		 public function delComms(){
		 	$gcid = Q('get.gcid',0,'intval');
			
			if($this->model->delete($gcid)){
				$this->success('删除成功');
			}else{
				$this->error('删除失败');
			}
			
		 }
		
	 }
	